package dialogs
{
	import Classes.pi_events;
	
	import UIFree.ObjectEvent;
	import UIFree.controls.uif_label;
	import UIFree.uif_component;
	
	import components.pj_albums;
	import components.pj_button;
	import components.pj_userInfo;
	import components.uif_tabItem;
	
	import editor.*;
	
	import flash.events.Event;
	import flash.geom.Rectangle;

	public class pi_albums extends pj_albums {
		public function pi_albums(parent: uif_component, list:Array, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, styleClass:String='') {
//			_albums = [{title: pi_data.FRIEND, smallTitle: pi_data.FRIEND, itemClass: null}].concat(list);
			super(parent, list, ax, ay, awidth, aheight, styleClass, false);
		}
		
		protected function getFriends(): void {
			app['externalserver'].getAllFriends(app['externalserver'].viewer_id, function(data: *): void {
				assignData(data, pi_userAvatar);
			}, pi_data.FRIEND_QUERYID);
		}
		
		override protected function updateLabels(): void {
			super.updateLabels();
			_label.text = (_albums.length > 1)?pi_data.USERPHOTOS:pi_data.NOALBUMS;
		}
		
		override public function assignList(list: Array): void {
			
			var friendsItem: Object;
			if (_albums && (_albums.length > 0)) friendsItem = _albums[0];
			else friendsItem = {title: pi_data.FRIEND, smallTitle: pi_data.FRIEND, itemClass: null};
			_albums = [friendsItem].concat(list);
			
			if (list.length == 0) pj.alert(pi_data.WARNING, pi_data.NOALBUMMESSAGE);

			super.assignList(_albums);
		}
		
		override protected function doChangeSelect(tabIndex: int): void {
			if (tabIndex == 0) getFriends();
			else super.doChangeSelect(tabIndex);
		}		
	}
}